// 住院管理
<template>
  <el-row>
    <el-col :span="24" class="section-option">
      <!-- <TopManu
       @handjsdata='handjsdata'
      ></TopManu> -->
    </el-col>
    <el-col :span="24">
     
      <el-col :span="24" class="hospitalNurse-right">
       <el-form :inline="true" class="demo-form-inline" v-model="formInline">
          <el-form-item label="搜索">
            <el-input
              placeholder="请输入姓名/门诊号/身份证号"
              v-model="formInline.rightKeyValue"
             
              @change="radiochang"
            >
   
            </el-input>
          </el-form-item>
          <el-form-item label='类型'>
              <el-select v-model="formInline.rightRadio"  @change="radiochang" multiple placeholder="类型">
    <el-option
      v-for="item in Radiooptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
          </el-form-item>
              <el-form-item label='范围'>
              <el-select v-model="formInline.range"  @change="radiochang"  placeholder="范围">
    <el-option
      v-for="item in Radiooptions2"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
          </el-form-item>
             <el-form-item label='病区'>
              <el-select v-model="formInline.room"  @change="radiochang"  placeholder="病区">
    <el-option
     
      label="全部"
      value="">
    </el-option>
    <el-option
      v-for="item in getBuildlist"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
          </el-form-item>
           <!-- <el-form-item label='时间'>
          <el-date-picker
      v-model="formInline.times"
      type="date"
      placeholder="选择日期"
      format="yyyy 年 MM 月 dd 日"
      value-format="yyyy-MM-dd"
      @change="radiochang">
    </el-date-picker>
          </el-form-item> -->
        </el-form>

        <el-table :data="patientlist" border style="width: 100%">
          <el-table-column prop="room_name" label="病区"> 
               <template slot-scope="scope">
                 {{scope.row.room_info[1]}}
                  </template> 
          </el-table-column>
          <el-table-column prop="room_name" label="房间">
             <template slot-scope="scope">
                 {{scope.row.room_info[2]}}
                  </template>  </el-table-column>
          <el-table-column prop="room_name" label="床位">
             <template slot-scope="scope">
                 {{scope.row.room_info[3]}}
                  </template>  </el-table-column>
          <el-table-column prop="member.name" label="姓名"> </el-table-column>
          <el-table-column prop="member.gender" label="性别"> </el-table-column>
          <el-table-column prop="member.age" label="年龄"> </el-table-column>
          <el-table-column prop="wallet.wallet_income" label="总押金">
          </el-table-column>
         
          <el-table-column prop="wallet.wallet_outcome" label="总费用">
          </el-table-column>
           <el-table-column prop="wallet.wallet_money" label="可用押金">
          </el-table-column>
           <el-table-column prop="get_node.deposit_warn" label="押金警示">
          </el-table-column>
           <el-table-column prop="wallet.wallet_outcome" label="已结金额">
          </el-table-column>
             <el-table-column prop="wallet.call_time" label="上次催缴时间">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-dropdown @command="handleCommand" trigger="click">
                <span class="el-dropdown-link">
                  更多<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <!-- <el-dropdown-item :command="[scope.row.id,scope.$index,'y']"
                    >押金</el-dropdown-item
                  > -->
                  <!-- <el-dropdown-item :command="[scope.row.id,scope.$index,'cxcy']">撤销申请出院</el-dropdown-item>
                  <el-dropdown-item :command="[scope.row.id,scope.$index,'sqcy']">申请出院</el-dropdown-item>
                 
       
                  <el-dropdown-item :command="[scope.row.id,scope.$index,'cxtj']">撤销出院</el-dropdown-item> -->

                     <el-dropdown-item :command="[scope.row.id,scope.$index,'yhxq']">详细信息</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
   <el-pagination
            background
            style="float:right"
            @size-change="handleSizeChange"
            :current-page="formInline.page"
            :page-sizes="[10, 20, 30, 100]"
            :page-size="formInline.limit"
            layout="sizes , total , prev, pager, next , jumper"
            @current-change="handlePagination"
            :total="total">
            </el-pagination>
      </el-col>
    </el-col>

    <!-- 押金弹框 -->
      

    <!-- <el-dialog :close-on-click-modal='false' title="出院结账" :visible.sync="zhuyuandeposit" width="70%">
        <infocrad :id="patientinfo.id" ref='userinfn'></infocrad>
     <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
  <el-radio-button :label="1">结账</el-radio-button>
  <el-radio-button :label="2">住院预结算</el-radio-button>
   <el-radio-button :label="3">医保结算</el-radio-button>
  <el-radio-button :label="4">住院结算撤销</el-radio-button>
</el-radio-group>
      <el-col :span="24">
      
        <jiezhang
          :patientinfo="patientinfo"
          ref="jiezhang"
          @jiezhang="jiezhang(arguments)"
        ></jiezhang>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click="zhuyuandeposit = false">取 消</el-button>
        <el-button type="success" @click="zhuyuanHospital">保 存</el-button>
      </div>
    </el-dialog> -->

       <el-dialog :fullscreen='true' :close-on-click-modal='false' title="用户详情" :visible.sync="userinfodeposit" width='70%'>
          

      <el-col :span="24">
         <infocrad :id='patientinfo.id' ref='userinfn'></infocrad>
        <costRecord :id='patientinfo.id' :uid='patientinfo.member.id' ></costRecord>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click="userinfodeposit = false">确定</el-button>
      
      </div>
    </el-dialog>
    

    <!-- 出院申请 -->
 
  
  </el-row>
</template>

<script>
import FromList from "@/forComponents/fromList/fromList";
import TopManu from "@/components/TopMenu";
import ViewTitle from "@/forComponents/viewTitle";
// import Create from "../components/create";
import jiezhang from "../components/jiezhang.vue";
import infocrad from "../components/infocrad.vue";
import costRecord from './comp/costRecord.vue'
import { getdictIndex } from "@/api/register";
import { getMemberDepositList } from "@/api/DepositList";
import { getOrganization } from "@/api/organization";
import { createDepositOrder,getNurseLevel,dischargeSettlement,getAllIcu,
cancelDischargeHospital,dischargeHospital,cancelSubmitHospital,hospSettA, hospSettPreSett,
  settCl, } from "@/api/zhuyanre"
let that;
export default {
  data() {
    return {
      isCollapse:1,
      wardData: [
        {
          wardName: "病区一",
          hold: 100,
          null: 0
        }
      ],
      wardTitle: [
        {
          prop: "name",
          name: "病区名称",
          type: 1,
          width: "140"
        },
        {
          prop: "full_bed_count",
          name: "占",
          type: 1
        },
        {
          prop: "empty_bed_count",
          name: "空",
          type: 1
        },
        {
          prop: "sex",
          name: "病区类型",
          type: 1
        }
      ],
      tableTitle: [
        {
          prop: "ipt_no",
          name: "住院号",
          type: 1,
          width: "80"
        },
        {
          prop: "name",
          name: "姓名",
          type: 1,
          width: "80"
        },
        {
          prop: "id_card",
          name: "身份证",
          type: 1
        }
      ],
      tableData: [
        {
          ipt_no: "",
          id: "",
          name: "",
          id_card: ""
        }
      ],
      leftValue: "",
      zhuyuandeposit:false,
      userinfodeposit:false,
       //查询条件
      formInline: {
        rightKeyValue: "",
        rightRadio:["2"],
        range:'3',
        room:'',
        page:1,
        limit:10,
        times:''
      },
      getBuildlist:[],
        Radiooptions:[{
          value: '1',
          label: '待入院'
        }, {
          value: '2',
          label: '在院'
        }, {
          value: '3',
          label: '申请出院'
        }, {
          value: '4',
          label: '待出院'
        }, {
          value: '5',
          label: '已出院'
        }],
        Radiooptions2:[{
            value: '1',
          label: '个人'
        },
        {
           value: '2',
          label: '科室'
        },
        { value: '3',
          label: '全院'}
        ],
      total:0,
      fooddialogdeposit: false,
      foodinfo: {
        id: "",
        pid: ""
      },
      NurseLeveldialogdeposit: false,
      nlevelinfo: {
        id: "",
        pid: ""
      },
       cancelDischarge:false,
        cancelDis: {
        hospital_id: "",
        msg: ""
      },
       chuyuanlogdeposit:false,
              dischargedata: {
        disease_arr: [],
        hospital_id: "",
        apply_time: "",
        leave_id: "",
        leave_way: "",
        leave_hospital: "",
        leave_remark: "",
        leave_yue:'',
        leave_type:'',
        department_id:'',
      },
      chuyuanfangshi:[],
      chuyuanzhuang:[],
      ben_list: [],
      patientlist: [],
      //当前病人信息
      patientinfo: {
        nurse_levelneme: "",
        member: {
          name: "",
          gender: "",
          age: ""
        },
        wallet: {
          wallet_income: ""
        },
        doctor: { real_name: "" },
        nurse: { real_name: "" },
        room_name: ""
      },

      //判断当前选中
      index_t: 0,
      dialogFormVisible1: false,
      dialogdeposit: false,
      //就病区{
      cancelHospitalinfo: {
        id: "",
        cancel_msg: ""
      },
      revoke: {
        id: "",
        cancel_msg: ""
      },
      //护士列表
      nuserlist: [],
      //医生列表
      duserlist: [],
      icuname: "",
      //押金
      orderinfo: {
        hospital_id: "",
        remark: "",
        des: "",
        payment: [
          {
            payment: 1,
            money: 0
          },
          {
            payment: 2,
            money: 0
          },
          {
            payment: 3,
            money: 0
          },
          {
            payment: 4,
            money: 0
          },
          {
            payment: 5,
            money: 0
          },
          {
            payment: 6,
            money: 0
          }
        ]
      },
      moneysum: 0,
      damoneysum: "",
      canceldialogdeposit: false,

      diet_list: [],
      huli: [],
      userdata: {},
      member_lv:[],
      disease:[]
    };
  },
  watch: {
    index(to) {
      if (to == 0) {
        that.loading.close();
      } else {
        that.loading = that.$loading({
          lock: true,
          text: "",
          background: "rgba(0, 0, 0, 0.7)"
        });
      }
    }
  },
  mounted() {
    that = this;
    that.getHospitalMember();
  this.getOrganization()
    // that.$refs.userinfn.readHospitalMemberDetail(patientinfo.id)
    that.getdiet_list()
  },
  methods: {
       getdiet_list() {
      getdictIndex({ group_id: "2,4,50,51" })
        .then(res => {
          let data = res.data;

          data.forEach((item, key) => {
            if(item.id==50){
               
             that.chuyuanzhuang=item.items;
            }else if(item.id==51){
            
             that.chuyuanfangshi=item.items;
            }else if (item.id==2){
              that.getBuildlist=item.items
            }else if (item.id==4) {
              that.member_lv=item.items
            }
            

           
          });
        })
        .catch(e => {});

    },
         getOrganization() {
      getOrganization().then(res => {
        console.log(res);
        this.departmentoptions = this.deleteChildren(res.data);
      });
    },
        deleteChildren(arr) {
      let childs = arr;
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children);
          } else {
            delete childs[i].children;
          }
        }
      }
      return arr;
    },
       //申请出院
  chuyuanHospital(){
      var  data=that.dischargedata
      data.disease_arr=that.patientinfo.disease
      data.hospital_id=that.patientinfo.id
      dischargeHospital(data).then(res=>{
            if(res.code==200){
              this.chuyuanlogdeposit=false
              that.dischargedata= {
                   disease_arr:[],
        hospital_id:'',
        apply_time:'',
        leave_id:'',
        leave_way:'',
        leave_hospital:'',
        leave_remark:''
              } 
               that.getHospitalMember()
            }
      })
  },
      //撤销出院申请
  cancelDischargehade(){
      var data=that.cancelDis
      data.hospital_id=that.patientinfo.id
      cancelDischargeHospital(data).then(res=>{
          if(res.code==200){
            this.cancelDischarge=false
            this.cancelDis={
              msg:'',
              hospital_id:''
            }
          }
      })
  },
      //获取护理等级
    getNurseLevel() {
      getNurseLevel({}).then(res => {
        that.huli = res.data;
      });
    },
    //  //获取病人性质
    //  getmember_lv() {
    //   getdictIndex({ group_id: 4 })
    //     .then(res => {
    //       let data = res.data[0].items;
    //       data.forEach((item, key) => {

    //         let arr = {
    //           name: item.name,
    //           id: item.id
    //         };
    //         that.member_lv.push(arr);
    //       });
    //     })
    //     .catch(e => {});
    // },
        handjsdata(){
         this.$router.push({
          path: "/workstation/jiezhang",
          query: { id: this.patientinfo.id }
        });
    },
    //分页
    handleSizeChange(e){
       this.formInline.limit = e
       that.getHospitalMember()
     },
        handlePagination(e){
 
       this.formInline.page = e
       that.getHospitalMember()
       },
       radiochang(){
          that.getHospitalMember()
       },
    getHospitalMember() {
      console.log(that.formInline.rightKeyValue)
      let data_t = {
        ipt_no: "",
        m_keyword: that.formInline.rightKeyValue,
        room: "",
        times:that.formInline.times,
        room:that.formInline.room,
        range:that.formInline.range,
         status: that.formInline.rightRadio.toString(),
        page: that.formInline.page,
        limit: that.formInline.limit
      };
      getMemberDepositList(data_t)
        .then(res => {
          let data = res.data.list;
          that.total = res.data.count;
         that.patientlist=[]
          if (data.length != 0) {
            
            data.forEach((item, key) => {
              let arr = {
                ipt_no: item.ipt_no,
                id: item.id,
                name: item.member.name,
                id_card: item.member.id_card
              };
              that.tableData.push(arr);
            });
            that.patientlist = data;
            for (var i in that.patientlist) {
              that.patientlist[i].member.gender =
                that.patientlist[i].member.gender == 1
                  ? "男"
                  : that.patientlist[i].member.gender == 2
                  ? "女"
                  : "其他";
                      that.patientlist[i].nurse_levelneme = that.mapping(
                that.patientlist[i].nurse_level
              );
               that.patientlist[i].memberNature=that.mapxing(
                 that.patientlist[i].member.nature
               )
            // that.patientlist[i].diseaseName =  that.patientlist[i].disease.map(item=>{
            //   return item.disease_name
            // })
            //  that.patientlist[i].diseaseName =  that.patientlist[i].diseaseName.join("&")
             
            }
            

            that.patientinfo = data[0];
          }
        })
        .catch(e => {
          this.$message({
            message: e.message,
            type: "error"
          });
        });
    },

     mapping(num) {
      //  console.log(that.huli,'000000000')
      var art = "";
      for (var i in that.huli) {
        if (that.huli[i].id == num) {
          // console.log(that.huli[i],'000000000')
          art = that.huli[i].name;
        }
        return art;
      }
    },
    //匹配斌人性质
     mapxing(num) {
      //  console.log(that.huli,'000000000')
      var art = "";
      for (var i in that.member_lv) {
        if (that.member_lv[i].id == num) {
          // console.log(that.huli[i],'000000000')
          art = that.member_lv[i].name;
        }
        return art;
      }
    },
 

    handleCommand(command) {
      console.log( command)
      let arr = command

 that.patientinfo = that.patientlist[arr[1]];
     
         switch (arr[2]) {
           //押金
         case 'jzcy':
     this.zhuyuandeposit=true
     that.getHospitalMember()
        break;
             case 'cxcy':
          that.cancelDischarge = true;
           that.getHospitalMember()
        break;
         case 'cxtj':
         this.$confirm("是否撤销提交出院", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消"
          }).then(() => {
            cancelSubmitHospital({
              hospital_id:  arr[0],
       
            }).then(res => {
              if(res.code==200){
       
                     this.$message({
          message: '撤销成功',
          type: 'success'
        });
                 
              }else{
                //  this.$message(res.message);
              }
               
            });
          });
        break;
        case 'sqcy':
          that.chuyuanlogdeposit=true
          //  that.getHospitalMember()
        break;
        case 'yhxq':
          that.userinfodeposit=true
          //  that.getHospitalMember()
        break;
       
          }
    },
      //结账出院
  zhuyuanHospital(){
        this.$refs.jiezhang.jiezhang()
  },
  jiezhang(arr) {
      console.log(arr[0]);
      if(this.isCollapse==1){
            dischargeSettlement(arr[0]).then(res => {
        if (res.code == 200) {
          this.zhuyuandeposit = false;
          this.$message({
            message: "结账成功",
            type: "success"
          });
        }
      });
      }else if (this.isCollapse==2) {
            hospSettPreSett(arr[0]).then(res => {
        if (res.code == 200) {
          this.zhuyuandeposit = false;
          this.$message({
            message: "结账成功",
            type: "success"
          });
        }
      });
      }else if (this.isCollapse==3) {
            hospSettA({id:this.patientinfo.id,psn_setlway:arr[0].psn_setlway}).then(res => {
        if (res.code == 200) {
          this.zhuyuandeposit = false;
          this.$message({
            message: "结账成功",
            type: "success"
          });
        }
      });
      }else if (this.isCollapse==2) {
            settCl(arr[0]).then(res => {
        if (res.code == 200) {
          this.zhuyuandeposit = false;
          this.$message({
            message: "结账成功",
            type: "success"
          });
        }
      });
      }

    },
        handedeposit() {
      var data_tt = that.orderinfo;
      data_tt.hospital_id = that.patientinfo.id;
      createDepositOrder(data_tt)
        .then(res => {
          let data = res.data;
         that.getHospitalMember()
          that.dialogdeposit = false;
        })
        .catch(e => {});
    },
    //押金总和
    moneysumfun() {
      var arr = that.orderinfo.payment;
      var num = 0;
      var num1 = that.NumberAdd(num, parseFloat(arr[0].money));
      var num2 = that.NumberAdd(num1, parseFloat(arr[1].money));
      var num3 = that.NumberAdd(num2, parseFloat(arr[2].money));
      var num4 = that.NumberAdd(num3, parseFloat(arr[3].money));
      var num5 = that.NumberAdd(num4, parseFloat(arr[4].money));
      that.moneysum = that.NumberAdd(num5, parseFloat(arr[5].money));
      that.damoneysum = that.AmountLtoU(that.moneysum);
    },
    AmountLtoU(num) {
      ///<summery>小写金额转化大写金额</summery>
      ///<param name=num type=number>金额</param>
      if (isNaN(num)) return "";
      var strPrefix = "";
      if (num < 0) strPrefix = "(负)";
      num = Math.abs(num);
      if (num >= 1000000000000) return "无效数值！";
      var strOutput = "";
      var strUnit = "仟佰拾亿仟佰拾万仟佰拾元角分";
      var strCapDgt = "零壹贰叁肆伍陆柒捌玖";
      num += "00";
      var intPos = num.indexOf(".");
      if (intPos >= 0) {
        num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
      }
      strUnit = strUnit.substr(strUnit.length - num.length);
      for (var i = 0; i < num.length; i++) {
        strOutput +=
          strCapDgt.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);
      }
      return (
        strPrefix +
        strOutput
          .replace(/零角零分$/, "整")
          .replace(/零[仟佰拾]/g, "零")
          .replace(/零{2,}/g, "零")
          .replace(/零([亿|万])/g, "$1")
          .replace(/零+元/, "元")
          .replace(/亿零{0,3}万/, "亿")
          .replace(/^元/, "零元")
      );
    },
  
  },
  components: {
    FromList,
    TopManu,
    ViewTitle,
      jiezhang,
    infocrad,
    costRecord
  }
};
</script>

<style lang="scss" scoped>
@import "./index.css";
.hosptal-patient {
}
.el-card__body {
  padding: 0px;
}

.hosptal-card {
  padding: 0px;
  width: 280px;
  min-height: 280px;
  box-sizing: border-box;
  font-family: "仿宋";
  .card-header {
    height: 80px;
    .card-header-img {
      width: 80px;
      height: 80px;
      border-radius: 60px;
    }
  }
  .card-title {
    font-weight: bold;
    font-size: 40px;
    text-align: center;
    background: #00ffff;
    height: 50px;
    line-height: 50px;
  }
  .card-span {
    font-size: 20px;
    color: #000000;
    font-weight: bold;
  }
  .card-span > div:nth-child(1) {
    padding-top: 10px;
  }
  .card-span > div:nth-child(2) {
    padding-top: 24px;
  }
  .card-radio {
    width: 30px;
    height: 30px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 30px;
    margin-top: 20px;
  }
  .card-label {
    display: flex;
    flex-wrap: wrap;

    // grid-template-columns: 1fr 1fr 1fr;
    // grid-gap:10px;
    div {
      margin-right: 10px;
      margin-bottom: 10px;
      padding: 0 10px;
      color: #fff;
      border-radius: 4px;
      background: #e9686b;
    }
  }
  .box_user {
  }
  .img_box {
    width: 46px;
    height: 46px;
  }
  .span_title {
    font-weight: bold;
  }
  .img_kong_box {
    margin: auto;
    width: 90%;
    margin-top: 90px;
  }
  .cardhover {
    width: 280px;
    min-height: 280px;
  }
  .cardhover:hover {
    background: #aeecd1c2;
  }
  .img_kong {
    width: 100%;
    height: auto;
    margin: auto;
  }
}
.separate {
    .dialog-text {
        font-size: 18px;
        margin-bottom: 20px;
        display: flex;
        justify-content: space-between;
    }
}
</style>